using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;

namespace DataEntity
{
	public class T_Report_ActualCollection : DBInteractionBase
	{
		#region Class Member Declarations
			private SqlDateTime		_report_ActualCollection_Date;
			private SqlDecimal		_report_ActualCollection_Amount;
			private SqlGuid			_report_ActualCollection_ID, _report_ActualCollection_MainID;
		#endregion


		public T_Report_ActualCollection()
		{
			// Nothing for now.
		}


	


		public override bool Update()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_ActualCollection_Update]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_ActualCollection_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_ActualCollection_ID));
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_ActualCollection_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_ActualCollection_MainID));
				cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_ActualCollection_Amount", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _report_ActualCollection_Amount));
				cmdToExecute.Parameters.Add(new SqlParameter("@daReport_ActualCollection_Date", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_ActualCollection_Date));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_ActualCollection::Update::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override bool Delete()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_ActualCollection_Delete]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_ActualCollection_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_ActualCollection_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_ActualCollection::Delete::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override DataTable SelectOne()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_ActualCollection_SelectOne]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Report_ActualCollection");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_ActualCollection_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_ActualCollection_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				if(toReturn.Rows.Count > 0)
				{
					_report_ActualCollection_ID = (Guid)toReturn.Rows[0]["Report_ActualCollection_ID"];
					_report_ActualCollection_MainID = (Guid)toReturn.Rows[0]["Report_ActualCollection_MainID"];
					_report_ActualCollection_Amount = (Decimal)toReturn.Rows[0]["Report_ActualCollection_Amount"];
					_report_ActualCollection_Date = (DateTime)toReturn.Rows[0]["Report_ActualCollection_Date"];
				}
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_ActualCollection::SelectOne::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		public override DataTable SelectAll()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_ActualCollection_SelectAll]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Report_ActualCollection");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_ActualCollection::SelectAll::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		#region Class Property Declarations
		public SqlGuid Report_ActualCollection_ID
		{
			get
			{
				return _report_ActualCollection_ID;
			}
			set
			{
				_report_ActualCollection_ID = value;
			}
		}


		public SqlGuid Report_ActualCollection_MainID
		{
			get
			{
				return _report_ActualCollection_MainID;
			}
			set
			{
				SqlGuid report_ActualCollection_MainIDTmp = (SqlGuid)value;
				if(report_ActualCollection_MainIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Report_ActualCollection_MainID", "Report_ActualCollection_MainID can't be NULL");
				}
				_report_ActualCollection_MainID = value;
			}
		}


		public SqlDecimal Report_ActualCollection_Amount
		{
			get
			{
				return _report_ActualCollection_Amount;
			}
			set
			{
				SqlDecimal report_ActualCollection_AmountTmp = (SqlDecimal)value;
				if(report_ActualCollection_AmountTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Report_ActualCollection_Amount", "Report_ActualCollection_Amount can't be NULL");
				}
				_report_ActualCollection_Amount = value;
			}
		}


		public SqlDateTime Report_ActualCollection_Date
		{
			get
			{
				return _report_ActualCollection_Date;
			}
			set
			{
				SqlDateTime report_ActualCollection_DateTmp = (SqlDateTime)value;
				if(report_ActualCollection_DateTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Report_ActualCollection_Date", "Report_ActualCollection_Date can't be NULL");
				}
				_report_ActualCollection_Date = value;
			}
		}
		#endregion
	}
}
